﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CdepartmentAdd2.aspx.cs"
    Inherits="ZLDC.Estate.TM.CdepartmentAdd2" %>

<%@ Register Src="../UserControl/Estate_Autocomplete.ascx" TagName="Estate_Autocomplete"
    TagPrefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>添加授权楼盘</title>
    <base target="_self" />
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../js/jquery/style/jquery.hiAlerts.css" rel="stylesheet" type="text/css" />

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/jquery/jquery.hiAlerts-min.js" type="text/javascript"></script>

    <script src="../js/jquery.autocomplete/jquery.autocomplete.min.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <script type="text/javascript">
        var currentPage = 1; // 当前页
        var pageSize = 10; // 每页显示多少条
        var pageall = 0; // 总页数
        var total = 0; // 总记录数

        // 读取列表
        $(function() {
            showList(currentPage);
        });

        // 条件查询资源列表

        function showList(currentPage) {
            var name = $("#iEstateName").val();
            if (name == "楼盘名称、拼音均可")
                name = "";

            $("#divList").html("<img src=\"../images/loading.gif\" />"); // 清空列表 
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=estate_list&page=' + currentPage + '&pagesize=' + pageSize + "&name=" + name,
                timeout: '10000',
                error: function() {
                    alert("系统繁忙,请稍候后试！");
                }, success: function(json) {
                    listCallBack(json);
                }
            });
        }

        /*
        功能: 将返回的json数据进行排版
        json: json数据
        */
        function listCallBack(response) {
            var json = eval("(" + response + ")");
            var record = json.record;

            if (record == null || record.length == 0) {
                $("#divList").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>"); 
                return;
            }

            var page = json.page;

            currentPage = page.currentpage;
            pageall = parseInt(page.pageall);
            total = page.total;

            var arr = [];
            arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
            arr.push("<tr>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("选择");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("序号");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("楼盘名称");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("城区");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("片区");
            arr.push("</td>");
            arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
            arr.push("地址");
            arr.push("</td>");
            arr.push("</tr>");

            var recordLength = record.length;
            for (var i = 0; i < recordLength; i++) {
                if (i % 2 == 0)
                    arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' >");
                else
                    arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' >");

                arr.push("<td height='20' class='STYLE6'>");
                arr.push("<input type='checkbox' name='checkbox_" + record[i].id + "' id='" + record[i].id + "' onclick=\"return addEstate(this, " + record[i].id + ")\" />");
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].id);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].name);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].cityname);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].areaname);
                arr.push("</td>");
                arr.push("<td height='20' class='STYLE6'>");
                arr.push(record[i].address);
                arr.push("</td>");
                arr.push("</tr>");
            }
            arr.push("</table>");
            $("#divList").html(arr.join('')); // 显示列表

            $("#divPage").html(""); // 清空
            if (pageall > 1) {
                var pageHtml = LexunJS.showPage(currentPage, pageall, "showList"); // 分页
                $("#divPage").html(pageHtml);
            }
        }

        // 条件查询
        function search() {
            $("#divList").html(""); // 清空列表        
            $("#divPage").html(""); // 清空分页
            showList(1);
        }

        // 添加|删除楼盘
        function addEstate(obj, estateid) {
            var deptid = LexunJS.GetQueryString("deptid");

            var isAdd = false;
            if (obj.checked)
                isAdd = true;

            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=department_estate_add&isadd=' + isAdd + '&estateid=' + estateid + '&deptid=' + deptid,
                timeout: '10000',
                error: function() {
                    alert("查询详情失败！");
                }, success: function(json) {
                    alert(json);
                }
            });

        }
    </script>

</head>
<body>
    <div id="divSearch" style="margin-top: 5px; text-align: center;">
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
            <tr>
                <td style="text-align: left; background-color: #FFFFFF; cursor: pointer;" valign="middle">
                    <span>楼盘名称:</span>&nbsp;<uc1:Estate_Autocomplete ID="Estate_Autocomplete1" runat="server" />
                    <input id="btnSearch" class="button_bak" type="button" value="查询" onclick="return search()" />
                </td>
                <td style="text-align: left; background-color: #FFFFFF; cursor: pointer;" valign="middle">
                </td>
            </tr>
        </table>
    </div>
    <div id="divHead" style="margin-top: 2px; margin-bottom: 2px;">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td height="24" bgcolor="#353c44">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td>
                                <img src="../images/tb.gif" width="14" height="14" /><span class="STYLE1">楼盘列表</span>
                            </td>
                            <td>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <div id="divList">
    </div>
    <div id="divPage">
    </div>
</body>
</html>
